import server from '@/config/server/index.js'
import dt from '@dt/dt'
import { userStore } from '@/store/user'

let key_historyInfo = 'user_history'
let historyInfo = dt.storage.get(key_historyInfo) || {} //

function post(path, auth = true, config = true) {
  return server.api().post(path).auth(auth).config(config)
}

function get(path, auth = true, config = true) {
  return server.api().get(path).auth(auth).config(config)
}

let api = {
  logout: post('/sa-oauth2/j_spring_security_logout'), //退出登录

  getPersonMessUpdate: post('/hft-portal/v1/user/update'), //更新登录人信息
  updatePwdCode: post('/hft-portal/noToken/verify/phoneCode'),
  code: post('/hft-portal/noToken/sendMessage', false, false),
  updatePwd: post('/hft-portal/user/updatePassword'),
  downloadCenter: {
    downloadlList: post('/hft-portal/v1/annex/record/pageAll'),
    downloadlUpdateStatus: post('/hft-portal/v1/annex/record/updateVerdict'),
    downloadlVerdict: post('/hft-portal/v1/annex/record/verdict')
  }
}

function logout() {
  return api.logout.fetch().then((res) => {
    userStore().logout()
    server.auth.clear()
  })
}

function getPersonMessUpdate(info) {
  return api.getPersonMessUpdate.fetch(info)
}

function downloadlList(info) {
  let params = {
    ...info,
    userId: userStore().info.userId
  }
  return api.downloadCenter.downloadlList.fetch(params).then((res) => {
    return res
  })
}

function downloadlUpdateStatus() {
  let info = {
    userId: userStore().info.userId
  }
  return api.downloadCenter.downloadlUpdateStatus.fetch(info).then((res) => {
    return res
  })
}

function downloadlVerdict() {
  let info = {
    userId: userStore().info.userId
  }
  return api.downloadCenter.downloadlVerdict.fetch(info).then((res) => {
    return res
  })
}
export default {
  logout,
  getPersonMessUpdate,
  downloadlList,
  downloadlUpdateStatus,
  downloadlVerdict
}
